package com.realtyreg.domain.entity.users;

import org.springframework.data.domain.Persistable;

import javax.persistence.*;

/**
 * Профиль пользователя.
 * Связь с пользователем: unidirectional one-to-one. Профиль знает всё о юзере, но юзер не знает о профиле ничего.
 * Created by Petro 22.12.12 22:14
 */
@Entity
@Table(name = "profile")
public class Profile implements Persistable<User> {
    private User user; //принципал
    private boolean isNew = false; //является ли профиль новым
    private String contact; //контактная информация
    private String personal; //личная информация
    private String career; //карьера
    private String specialization; //специализация

    public Profile() {
    }

    public Profile(User user) {
        this.user = user;
        isNew = true;
    }

    public String toString() {
        return "Profile{" +
                "user=" + user +
                '}';
    }

    public int hashCode() {
        return user.hashCode();
    }

    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (!(obj instanceof Profile))
            return false;

        Profile other = (Profile) obj;
        if (user == null || other.getUser() == null)
            return false;
        if (user.getId() == null || other.getUser().getId() == null)
            return false;
        return user.getId().equals(other.getUser().getId());
    }

    @Transient
    public User getId() {
        return user;
    }

    @Transient
    public boolean isNew() {
        return isNew;
    }

    @Id
    @OneToOne(cascade = CascadeType.REMOVE, optional = false)
    @JoinColumn(name="user_id", unique = true, nullable = false)
    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @Column
    public String getContact() {
        return contact;
    }

    public void setContact(String contact) {
        this.contact = contact;
    }

    @Column
    public String getPersonal() {
        return personal;
    }

    public void setPersonal(String personal) {
        this.personal = personal;
    }

    @Column
    public String getCareer() {
        return career;
    }

    public void setCareer(String career) {
        this.career = career;
    }

    @Column
    public String getSpecialization() {
        return specialization;
    }

    public void setSpecialization(String specialization) {
        this.specialization = specialization;
    }
}
